<template>
	<view class="repair-wrap">
		<view style="border-top: 1px solid #F7F8F9;">
			<view style="width: 100%;background-color: #FFFFFF; background-color: #f4f4f4;">
				<view style="width: 95%;margin: 10px auto;background-color: #FFFFFF;padding: 0 20px;">
					<view
						style="border-bottom: 1px solid #eeeeee;padding-bottom: 15px;padding-top: 20px;display: flex;">
						<view class="u-font-32"> 
						   <text style="color: red;">*</text>
						   <text style="font-weight: 600;">被投诉员工：</text>
						</view>
						<span v-if="emp.length == 0" class="employee_complained_against">请在下方选择被检举的员工</span>
						<view class="complete_chu" v-for="(item,index) in emp">
							<text class="complete_chuTxt">{{ item.employee_name }}</text>
							<text @click="handlerDel(item.employee_id)"
								style="color: #F9A832;margin-left: 9px;font-size: 15px;">x
							</text>
						</view>
					</view>
					<view class="be-complained">
						<image src="https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/searchCrew.png" class="tel" />
						<view style="font-size: 16px;color: #4A90E2 ;" @click="newly()">添加被投诉员工</view>
					</view>
				</view>
			</view>
			<view style="width: 100%;margin: 25px auto;background-color: #FFFFFF;">
				<view style="width: 95%;margin: 25px auto;padding-bottom: 20px;padding: 0 20px;margin-top: -10px;">
					<view style="padding-top: 20px;padding-bottom: 10px;">
						<view class="u-font-32"> 
						    <text style="color: red;">*</text>
							<text style="font-weight:600;">投诉原因：</text>
						</view>
						<view>
							<view class='guar-text'>
								<textarea v-model="ruleForm.comp_reason" maxlength='-1' type="textarea"
									placeholder="请输入详细描述" />
							</view>
							<p style="color: #999999; margin-top: 10px;">提示:请放心进行检举揭发,我将会对您的信息进行保密,您反应的问题,一经查实,定会严肃处理!
							</p>
						</view>
					</view>
				</view>
			</view>
			<view style="width: 100%;margin: 25px auto;background-color: #FFFFFF;">
				<view
					style="width: 95%;margin: 25px auto;padding-bottom: 20px;padding: 0 20px;margin-top: -10px;box-sizing: border-box;">
					<view style="padding-top: 5px;">
						<view class="guarn-box u-m-t-20">
							<view class="u-font-28 u-m-b-45" style="display: flex" v-if="images.length < 3">
								<h3> <text style="color: red;">*</text>
									<!-- 证据图片： -->
								</h3>
								<image style="width: 20px;height: 18px;margin-right: 3px;padding-top: 3px;"
									src="https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/uploading.png" @click="uoloadHouse">
								</image>
								<view style="font-size: 14px; font-weight: 700; color: blue;padding-top: 2px"
									@click="uoloadHouse">
									点击上传证据图片
								</view>
							</view>
							<view class="img-upload">
								<!-- //上传完的图片 -->
								<view v-if="images.length > 0"
									style="display: flex;justify-content: space-between; width: 100%;">
									<view class="img-list" v-for="(item,index) in images">
										<image class="process-img" @click="preview(item)" :src="item"
											mode="aspectFill" />
										<image class="close" @click="handlerDeletedImages(item)"
											src="https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/close.png" />
									</view>
								</view>
							</view>
							<view class="guarn-box-txt">
								<view class="u-font-28 u-m-b-10">
									提示：最多上传3张照片
								</view>
								<view class="u-font-28 u-m-b-10">
									请上传根本事件相关的清晰图片，以便物业公司上级进行处理
								</view>
							</view>
						</view>
					</view>
				</view>
				<view style="margin-top: 20px;padding-bottom: 20px;">
					<button class="confirm_submit" @click="handlerSubmit()">提交</button>
				</view>
			</view>

		</view>

		<view v-if="isActive==1" style="border-top: 1px solid #F7F8F9;">
			<view style="width: 100%;background-color: #FFFFFF;">
				<view v-if="tableData.length === 0">
					<view style="width: 232px;height: 242px;margin: 0px auto;">
						<image style="width: 100%;height: 100%;margin-top: 100px;"
							src="https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/zanwushuju.png" mode=""></image>
					</view>
					<view style="width: 62%;margin: 122px auto;text-align: center;color: #999;">暂无数据</view>
				</view>
				<view
					style="width: 95%;margin: 10px auto;background-color: #FFFFFF;padding-top: 20px;padding-bottom: 20px;"
					v-for="(item,index) in tableData" @click="navTo('/pages/complaint/detailcomplaint',item.id)">
					<view>
						<text>被投诉人：{{ item.comp_cover_name }}</text>
						<view style="float: right;">
							<text v-if="item.comp_handler_state == 1" style="color: #F9A832 ;">待处理</text>
							<text v-if="item.comp_handler_state == 2" style="color: rgb(50 240 249);">处理中</text>
							<text v-if="item.comp_handler_state == 3" style="color: rgb(249 50 50) ;">已处理</text>
						</view>
					</view>

					<view style="margin-top: 15px;">
						<text>投诉原因：{{ item.comp_reason }}</text>
					</view>

					<view class="pendingMain_img" v-if="item.comp_images">
						<view class="Main_img" v-for="ite in item.comp_images">
							<image class="Main_imgI" :src="ite" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		pathToBase64,
		base64ToPath
	} from '@/utils/image-tool.js'

	export default {
		data() {
			return {
				type: 1,
				index: 0,
				array: ['分类', '分类二'],
				buttonClick: 0,
				buttonDay: 0,
				isActive: 0, //0.填写投诉  1.我的投诉
				inday: 0,
				navList: [{
					index: 0,
					title: '填写服务'
				}, {
					index: 1,
					title: "我的投诉"
				}],
				ruleForm: {
					user_id: uni.getStorageSync('rawData').userId, //用户id
					// user_id:2141,//用户id
					comp_init_id: null, //投诉人id 员工或业主id
					comp_type: 2, //投诉类型 1.员工投诉 2.业主投诉
					comp_cover: null, //被投诉人
					comp_reason: null, //投诉原因
					comp_images: null, //投诉凭证
				},
				indexList: true,
				emp: [],
				images: [],
				homelist: {},
				tableData: [],
				pageInfo: {
					page: 1,
				},
			}
		},
		onShow() {
			let _this = this
			if (uni.getStorageSync('phone')) {
				if (uni.getStorageSync('loginFlag')) {
					if (!uni.getStorageSync('hourseList')) {
						this.$openInvite()
					} else {
						_this.showFlag = true
						_this.homelist = uni.getStorageSync('hourseList')[uni.getStorageSync('hourseNum') || 0]
						_this.name = _this.homelist.proName;
						_this.address = _this.homelist.buildDistrictCode + '-' + _this.homelist.buildTowerCode + '-' +
							_this.homelist.roomUnitNumber + '-' + _this.homelist.roomCode
					}
				} else {
					uni.showModal({
						title: '请先实名认证',
						showCancel: false,
						confirmText: '确认',
						confirmColor: '#F9A832',
						success: function(res) {
							if (res.confirm) {
								_this.$Router.push({
									path: '/homePage1/realName/realName'
								})
							}
						}
					});
				}
			} else {
				uni.showModal({
					title: '请先登录',
					showCancel: false,
					confirmText: '确认',
					confirmColor: '#F9A832',
					success: function(res) {
						if (res.confirm) {
							console.log('a')
							_this.$Router.pushTab({
								path: '/pages/user/user'
							})
						}
					}
				});
			}
			this.homelist = uni.getStorageSync('hourseList')[uni.getStorageSync('hourseNum') || 0]
			this.selectOwn(this.homelist.roomId);
			// this.selectOwn(16822);
			this.handlerGetTableData();
		},
		onPullDownRefresh() {
			let _this = this
			if (uni.getStorageSync('phone')) {
				if (uni.getStorageSync('loginFlag')) {
					if (!uni.getStorageSync('hourseList')) {
						uni.showModal({
							title: '请先进行业主认证',
							showCancel: false,
							confirmText: '确认',
							confirmColor: '#F9A832',
							success: function(res) {
								if (res.confirm) {
									_this.$Router.push({
										path: '/my/address/address'
									})
								}
							}
						});
						this.$openInvite()
					} else {
						_this.showFlag = true
						_this.homelist = uni.getStorageSync('hourseList')[uni.getStorageSync('hourseNum') || 0]
						_this.name = _this.homelist.proName;
						_this.address = _this.homelist.buildDistrictCode + '-' + _this.homelist.buildTowerCode + '-' +
							_this.homelist.roomUnitNumber + '-' + _this.homelist.roomCode
						// _this.getRepaireClass()
					}
				} else {
					uni.showModal({
						title: '请先实名认证',
						showCancel: false,
						confirmText: '确认',
						confirmColor: '#F9A832',
						success: function(res) {
							if (res.confirm) {
								_this.$Router.push({
									path: '/homePage1/realName/realName'
								})
							}
						}
					});
				}
			} else {
				uni.showModal({
					title: '请先登录',
					showCancel: false,
					confirmText: '确认',
					confirmColor: '#F9A832',
					success: function(res) {
						if (res.confirm) {
							console.log('a')
							_this.$Router.pushTab({
								path: '/pages/user/user'
							})
						}
					}
				});
			}
			this.homelist = uni.getStorageSync('hourseList')[uni.getStorageSync('hourseNum') || 0]
			// this.selectOwn(this.homelist.roomId);
			// this.selectOwn(16822);
			this.handlerGetTableData();
			uni.stopPullDownRefresh()
		},
		methods: {
			selectOwn(room_id) {
				this.$request.api.getNeed({
					type: 2,
					room_id: room_id,
				}).then(res => {
					this.ruleForm.comp_init_id = res.data.data.owner_id;
				})
			},
			checked(index) {
				this.isActive = index
			},
			newly() {
				uni.navigateTo({
					url: '/my/complaint/continue'
				})
			},
			//跳转
			navTo(url, id) {
				uni.navigateTo({
					url: url + "?id=" + id
				});
			},
			shouList() {
				this.indexList = !this.indexList
			},
			//接收选择的员工
			otherFun(object) {
				if (object) {
					if (this.emp.length > 0) {
						let state = 1; //默认没有 1没有 2有
						for (let i = 0; i < this.emp.length; i++) {
							if (this.emp[i].employee_id == object.employee.employee_id) {
								state = 2;
							}
						}
						if (state == 1) {
							this.emp.push(object.employee);
						}
					} else {
						this.emp.push(object.employee);
					}
				}
			},
			//删除选中的人
			handlerDel(employee_id) {
				let ee = this.emp;
				this.emp = [];
				if (ee.length > 0) {
					for (let i = 0; i < ee.length; i++) {
						if (ee[i].employee_id != employee_id) {
							this.emp.push(ee[i]);
						}
					}
				}
			},
			// 选择图片
			uoloadHouse() {
				if (this.images.length < 3) {
					let _this = this;
					uni.showActionSheet({
						itemList: ['手机拍照', '本地图片上传'],
						success: function(res) {
							uni.showLoading({
								title: '上传中'
							});
							if (res.tapIndex == 0) {
								uni.chooseImage({
									count: 1, //默认9
									sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
									sourceType: ['camera '],
									success: function(res) {
										_this.imgFile = res.tempFilePaths[0];
										pathToBase64(res.tempFilePaths[0]).then(res => {
											_this.subFlag = true;
											_this.$request.api.image({
												imageBase64: res
											}).then(res => {
												_this.subFlag = false;
												_this.images.push(res.data.data)
												uni.hideLoading();
											})
										})
									}
								})
							} else {
								uni.chooseImage({
									count: 1, //默认9
									sizeType: ['original', 'compressed'],
									sourceType: ['album  '],
									success: function(res) {
										_this.imgFile = res.tempFilePaths[0];
										pathToBase64(res.tempFilePaths[0]).then(res => {
											_this.subFlag = true;
											_this.$request.api.image({
												imageBase64: res
											}).then(res => {
												_this.subFlag = false;
												_this.images.push(res.data.data)
												uni.hideLoading();
											})
										})
									}
								});
							}
						},
						fail: function(res) {}
					});
				}
			},
			// 图片预览
			preview(item) {
				uni.previewImage({
					urls: [item],
					current: 0,
					longPressActions: {
						success: function(data) {
							console.log(data)
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err)
							console.log(err.errMsg);
						}
					}
				});
			},
			//删除图片
			handlerDeletedImages(item) {
				let images = this.images;
				this.images = [];
				if (images.length > 0) {
					for (let i = 0; i < images.length; i++) {
						if (images[i] != item) {
							this.images.push(images[i]);
						}
					}
				}
			},
			//提交按钮
			handlerSubmit() {
				if (this.emp.length <= 0) {
					uni.showToast({
						title: "请至少选择一个被投诉人",
						success: "400",
						icon: 'none'
					})
					return;
				}
				let e = [];
				for (let i = 0; i < this.emp.length; i++) {
					e.push(this.emp[i].employee_id);
				}
				this.ruleForm.comp_cover = e.toString();
				if (!this.ruleForm.comp_reason) {
					uni.showToast({
						title: "请输入投诉原因",
						success: "400",
						icon: 'none'
					})
					return;
				}
				if (this.images.length <= 0) {
					uni.showToast({
						title: "请至少上传一张照片",
						success: "400",
						icon: 'none'
					})
					return;
				}
				this.ruleForm.comp_images = this.images.toString();
				this.$request.api.addComp({
					user_id: this.ruleForm.user_id,
					comp_init_id: this.homelist.ownerId,
					comp_type: this.ruleForm.comp_type,
					comp_cover: this.ruleForm.comp_cover,
					comp_reason: this.ruleForm.comp_reason,
					comp_images: this.ruleForm.comp_images,
				}).then(res => {
					this.ruleForm.comp_cover = null;
					this.ruleForm.comp_reason = null;
					this.ruleForm.comp_images = null;
					this.emp = [];
					this.images = [];
					uni.showToast({
						title: "投诉增加成功！",
						success: "200"
					})
					setTimeout(() => {
						uni.redirectTo({
							url: '/pages/complaint/complaintList'
						}, 400)
					})
				})
			},
			//处理获取列表数据
			handlerGetTableData() {
				this.$request.api.getComp({
					pageIndex: this.pageInfo.page,
					user_id: uni.getStorageSync('rawData').userId,
					// user_id:2141,
				}).then(res => {
					if (this.pageInfo.page == 1) {
						this.tableData = res.data.data.datalist;
					} else {
						this.tableData.push(...res.data.data.datalist)
					}
				})
			},
		}
	}
</script>


<style lang="scss">
	.repair-wrap {
		width: 100%;
		height: auto;
		background: #f4f4f4;
		overflow: hidden;

		.repair-box {
			background: #fff;

			.repair-titel {
				height: 22px;
				line-height: 22px;

				.repair-titel-l {
					float: left;
				}

				.repair-titel-r {
					float: right;
					color: #999;
				}
			}

			.repair-6 {
				color: #666;
			}
		}
	}

	.guar-text textarea {
		width: 100%;
		margin-top: 21px;
		border-radius: 8px;
		height: 120px;
		background: #F2F3F5;
		padding: 8px 10px !important;
		box-sizing: border-box;
	}

	.guarn-box {
		width: 100%;
		//height: 216rpx;
	}

	.guarn-box2 {
		display: flex;
	}

	.guarn-box2-img {
		width: 108px;
		height: 108px;
		margin-right: 10px;
		position: relative;

		.guarn-box2-img-close {
			position: absolute;
			top: 10px;
			right: 10px;
		}
	}

	.guarn-box2 image {
		width: 108px;
		height: 108px;
	}

	.guarn-box-img {
		width: 108px;
		height: 108px;
		float: left;
		margin-right: 12px;
		text-align: center;
		border: 1px solid #ccc;
		border-radius: 2px;
	}

	.guarn-box-img image {
		width: 38px;
		height: 34px;
	}

	.guarn-box-txt {
		// width: 420rpx;
		//height: 216rpx;
		color: #999;
		//float: left;
		margin-top: 15px;
	}

	.guar-txt-time {
		float: right;
		text-align: right;
		width: 201px;
	}

	.tab_nav {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.tab_nav .navTitle {
		height: 45px;
		line-height: 45px;
		width: 100%;
		text-align: center;
		font-size: 16px;
		font-family: Alibaba PuHuiTi;
		color: #333;
	}

	.active {
		position: relative;
		color: #417505;
	}

	.active::after {
		content: "";
		position: absolute;
		width: 50px;
		height: 2px;
		background-color: #417505;
		left: 0px;
		right: 0px;
		bottom: 0px;
		margin: auto;
	}

	.confirm_submit {
		width: 80%;
		height: 42px;
		background: linear-gradient(180deg, #76D904 0%, #417505 100%);
		border-radius: 22px;
		line-height: 42px;
		color: #FFFFFF;
		text-align: center;
		font-size: 16px;
	}

	.complete_chu {
		background-color: rgba(249, 168, 50, 0.2);
		width: 22%;
		line-height: 22px;
		font-size: 11px;
		border-radius: 9px;
		position: relative;
		margin-left: 10px;
		color: #578EF0;
		margin-top: -2px;
		height: 25px;
	}

	.complete_chuTxt {
		margin-left: 17.5px;
	}

	.pendingMain_img {
		display: flex;
		width: 125px;
		margin-top: 15px;

		.Main_img {
			flex: 1;
			height: 100px;
			padding: 0 10px;

			.Main_imgI {
				width: 100%;
				height: 100%;
				border-radius: 7.5px;
			}
		}
	}

	/*被诉人提示文字*/
	.employee_complained_against {
		color: #999999;
		margin-top: 2px;
	}

	/*选择被投诉人*/
	.be-complained {
		padding-bottom: 15px;
		padding-top: 10px;
		display: flex;
		justify-content: center;
		/* 水平居中 */
		align-items: center;
		/* 垂直居中 */
	}

	/* +号图片 */
	.tel {
		width: 18px;
		height: 18px;
		margin-right: 10px;
	}

	.img-upload {
		display: flex;
		margin-bottom: -10px;

		.img-list {
			width: 200rpx;
			height: 200rpx;
			// margin-right: 14px;
			position: relative;

			.process-img {
				width: 100%;
				height: 100%;
				border-radius: 4px;
			}

			.close {
				width: 12px;
				height: 12px;
				position: absolute;
				right: -5px;
				top: -5px;
			}
		}

		.img-up {
			width: 63px;
			height: 63px;
			border-radius: 4px;
			border: 0.5px dashed #CCC;
			background: url(https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/upload_img_icon.png) center center no-repeat;
			background-size: 17px 17px;
		}

		.video-up {
			width: 63px;
			height: 63px;
			border-radius: 4px;
			border: 0.5px dashed #CCC;
			background: url(https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/upload_video_icon.png) center center no-repeat;
			background-size: 17px 17px;
		}

		hr {
			margin-top: 10px;
		}
	}
</style>